package com.nuoniu.sibanyun.controller.erp;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpProjectTask;
import com.nuoniu.sibanyun.service.erp.IErpProjectTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 项目任务 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-25
 */
@RestController
@RequestMapping("/project/task")
@Api(tags = "项目任务管理")
public class ErpProjectTaskController extends BaseController {

    @Autowired
    private IErpProjectTaskService taskService;

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList(Integer projectId) {
        return HttpResult.ok(taskService.getList(projectId));
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpProjectTask projectTask) {
        if(projectTask.getProjectId() == null) {
            throw new NuoNiuException("未知的项目");
        }

        if(projectTask.getPlanId() == null) {
            throw new NuoNiuException("未知的计划");
        }

        if(StringUtils.isBlank(projectTask.getTitle())) {
            throw new NuoNiuException("任务标题不能为空");
        }

        taskService.saveTask(projectTask);
        return HttpResult.ok();
    }

    @ApiOperation("删除任务")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        taskService.removeById(id);
        return HttpResult.ok();
    }
}
